/**
 * 相关案例的详情的逻辑处理
 * Created by Administrator on 2016/12/29.
 */

module.exports = function ($scope, $rootScope, caseBarDetailAnLiDetailService,$anchorScroll,$location,$cookies) {

    //搜索条件
    var caseid= $cookies.get('correlationCABEID');

    //标题
    $scope.mCaseheadline=$cookies.get('mCaseheadline');



    $scope.init = function () {
        $scope.CorrelationCabe(caseid);
    };

    // 案件详情列表
    $scope.CorrelationCabe = function (caseid) {
        $rootScope.loadingShow = true;
        $rootScope.fadeShow = true;

        caseBarDetailAnLiDetailService.demandID(caseid).then(function (data) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
           /* //设置下载ID
            $scope.downloadid=downloadid;*/

            //设置详情类容
            setlist((JSON.parse(data.data)).detail);

        }, function (response) {
            //console.error('updatemessage error', response.status, response.statusText);
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
        });
    };


    $scope.init();

    //处理非列表数据
    function setlist(detail) {
        //标题
        $scope.Causes = detail.causes;
        //来源
        $scope.caseSource = detail.caseSource;

        setlistbody(detail);
    }

    //处理列表数据
    function setlistbody(detail) {
        //文书正文的列表
        var keyMap = {
            "PartyInfo": "当事人信息",
            "HearProcess": "审理经过",
            "PlaintiffReport": "原告诉称",
            "AccusedArgued": "被告辩称",
            "CourtInquire": "本院查明",
            "CourtMaintaine": "  本院认为",
            "UmpireResult": "裁判结果",
            "JudgeStuff": "审判人员",
            "JudgementDate": " 裁判日期",
            "Clerk ": "书记员",
            "CollegiateBench": "合议庭"
        }
        //基本信息的列表
        var informationkeyMap = {
            "LegalInstrumentType": "文书性质",
            "CaseType": "案件类别",
            "Causes": "案由",
            "PlaintiffName": "原告名称",
            "PlaintiffLawyer": "  原告律师 ",
            "PlaintiffLawFirm": " 原告律师所属律所",
            "AccusedName": "被告名称",
            "AccusedLawyer": " 被告律师",
            "AccusedLawFirm": "被告律师所属律所",
            "JudgementCourtName": "审判法院名称"
        }
        //暂时不用的字段
        var instroMap={
            "CaseCode": "案号",
            "CaseSource": "裁判书来源",
            "QuotesLegislation": "引用法规",
            "ControversyPoint": "争议焦点",
            "JudgeName": "法官",
            "Supplement": "附录"
        }
        var information=[];
        var sss = [];

        /**去除空元素*/
        for (var key in detail) {
            if (detail[key] != "") {
                if (detail[key] != null) {
                    if (keyMap[key]) {
                        var oo = new Object();
                        oo.name = key;
                        oo.body = detail[key];
                        oo.headline = keyMap[key];
                        sss.push(oo);
                    }else if(informationkeyMap[key]){
                        var oo = new Object();
                        oo.name = key;
                        oo.body = detail[key];
                        oo.headline = informationkeyMap[key];
                        information.push(oo);
                    }
                }else {
                   // console.log(key,"------");
                }

            }else {
              // console.log(key,"------");
            }

        }

        $scope.CaseMainTxt = sss

       /* for(var key in sss){
            if(informationkeyMap[sss[key].name]){
                information.push(sss[key]);
            }
        }*/
        $scope.CaseMainTxt2 = information
    }


    //侧边栏锚点定位
    $scope.Anchor = function (name) {
        $anchorScroll.yOffset = 150;// 总是滚动额外的50像素
        $location.hash(name);
        // 调用 $anchorScroll()
        $anchorScroll();
    };

    //左翻页
    $scope.leftpaging=function () {
        if(pagination>1){
            pagination=(parseInt(pagination)-1);
            $scope.CorrelationCabe((pagination-1), "1", objstr);
        }else {
            alert("已经是第一页");
        }

    }

    //左翻页
    $scope.rightpaging=function () {
        if(pagination<parseInt(sumpaging)){
            pagination=(parseInt(pagination+1));
            $scope.CorrelationCabe((pagination-1), "1", objstr);
        }else {
            alert("已经是第最后一页");
        }

    }
}


